package com.bfsuol.yihang.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.bfsuol.bfsuolframework.core.controller.SpringControllerSupport;
import com.bfsuol.bfsuolframework.core.controller.support.Pagination;
import com.bfsuol.bfsuolframework.core.controller.support.QueryParam;
import com.bfsuol.bfsuolframework.core.spring.QueryParameter;
import com.bfsuol.bfsuolframework.security.annotations.SecList;
import com.bfsuol.bfsuolframework.security.annotations.SecPrivilege;
import com.bfsuol.yihang.cars.api.CommandVehicleService;
import com.bfsuol.yihang.cars.api.QueryVehicleService;
import com.bfsuol.yihang.cars.dto.VehicleDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

@Controller
@RequestMapping("/yihang/insure")
public class VehicleInsureController extends SpringControllerSupport {

    @Autowired
    private QueryVehicleService queryVehicleService;

    @Autowired
    private CommandVehicleService commandVehicleService;

    @SecPrivilege(title = "投保管理")
    @RequestMapping("/index")
    public ModelAndView index(Model model){
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.setViewName(getViewNamedPath("index"));
        return modelAndView;
    }

    @SecList
    @RequestMapping("/list")
    public ModelAndView list(
            VehicleDTO vehicleDTO,
            @ModelAttribute("page") Pagination page){

        vehicleDTO.setIsSearchExpireDaysCar(true);
        com.baomidou.mybatisplus.extension.plugins.pagination.Page page1 = new Page(page.getDefaultCurrentPage(),page.getPageSize());
        com.baomidou.mybatisplus.extension.plugins.pagination.Page vehiclePages = queryVehicleService.page(page1,vehicleDTO);
        page.setItems(vehiclePages.getRecords());
        page.setTotalRecord((int) vehiclePages.getTotal());

        ModelAndView modelAndView = new ModelAndView();
        modelAndView.setViewName(getViewNamedPath("list"));
        return modelAndView;
    }
}
